package com.weilele.leisure.time.ui.view.video

import android.content.Context
import android.util.AttributeSet
import android.view.View
import androidx.appcompat.widget.AppCompatTextView
import com.weilele.leisure.time.ui.dialog.SelectListPopupWindow
import com.weilele.mvvm.utils.android_r.fullScreen
import com.yizisu.playerlibrary.IYzsPlayer
import com.yizisu.playerlibrary.view.video_view.helper.IPlayerConfig
import com.yizisu.playerlibrary.view.video_view.helper.IPlayerHelper

class PlayerSelectListText : AppCompatTextView, IPlayerHelper {
    constructor(context: Context) : super(context)
    constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)
    constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(
        context,
        attrs,
        defStyleAttr
    )

    override fun onAttachPlayerConfig(playerConfig: IPlayerConfig) {
        super.onAttachPlayerConfig(playerConfig)
        setOnClickListener {
            playerConfig.playerControllerBarHelperData.value?.hide(0)
            SelectListPopupWindow.show(it)?.apply {
                setOnDismissListener {
                    postDelayed({
                        fullScreen(true)
                    }, 200)
                }
            }
        }
    }

    override fun onDetachedPlayerConfig(playerConfig: IPlayerConfig) {
        super.onDetachedPlayerConfig(playerConfig)
        setOnClickListener(null)
    }
}